<template>
  <div>
    <!-- 登录后的上半 -->
    <div class="loginup" v-if="token">
      <!-- 上半图 -->
      <div class="uppic"></div>
      <!-- 上半下白 -->
      <div class="updown">
        <!-- 圆形 -->
        <div class="yuan">
          <!-- 头像 -->
          <div class="avatar"></div>
        </div>
        <!-- 用户名 -->
        <div class="you">{{nickname}}</div>
        <!-- 退出登录 -->
        <button class="outlogin" @click="loginout">退出登录</button>
        <!-- 编辑个人资料 -->
        <div class="usermsg">编辑个人资料</div>
      </div>
    </div>
    <!-- 没登录的上半 -->
      <div class="up" v-else>
      <!-- 上半图 -->
      <div class="uppic"></div>
      <!-- 上半下白 -->
      <div class="updown">
        <!-- 圆形 -->
        <div class="yuan">
          <!-- 头像 -->
          <div class="avatar"></div>
        </div>
        <!-- 用户名 -->
        <div class="youke">游客</div>
        <!-- 去登录 -->
        <button class="login" @click="loginFn">去登录</button>
      </div>
    </div>
    <!-- 导航组件 -->
<van-grid :column-num="3">
  <van-grid-item icon="star-o" text="我的收藏" to="/0-Collection"/>
  <van-grid-item icon="wap-home-o" text="我的出租"  to="/my-lease"/>
  <van-grid-item icon="clock-o" text="看房记录" />
  <van-grid-item icon="vip-card-o" text="成为房主" />
  <van-grid-item icon="contact" text="个人资料" />
  <van-grid-item icon="service-o" text="联系我们" />
</van-grid>
    <!-- 图片 -->
    <div class="downpic">

    </div>
  </div>
</template>

<script>
// import request from '@/utils/request'
import { getUserData } from '@/api/article'
import { getToken, delToken } from '@/utils/storage'
export default {
  async created () {
    const res = await getUserData()
    console.log(res)
    this.nickname = res.body.nickname
  },
  data () {
    return {
      active: 0,
      nickname: ''
    }
  },
  methods: {
    loginFn () {
      this.$router.push('/login')
    },
    loginout () {
      delToken()
      this.$router.push('/login')
    }
  },
  computed: {
    token () {
      return getToken()
    }
  }
}
</script>

<style lang='less' scoped>
.loginup{
  width: 100%;
  height: 51.1vh;
  position: relative;
  margin-bottom: 2vh;
   .uppic{
    width: 100%;
    height: 51.1vh;
    // background-color: saddlebrown;
    position: absolute;
    left: 0;
    top: 0;

      background-image: url('@/assets/nvtou.png');
      // background: cover;
      background-size: cover;

  }
  .updown{
    width: 48.2vh;
    height: 26vh;
    background-color: #fff;
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-24.1vh);
    // position: relative;
    box-shadow: 0 0 10px 3px #ddd;
    .you {
      margin-top: 6vh;
      margin-left: 18.5vh;
      font-size: 12px;
    }
    .youke{
      margin-top: 6vh;
      margin-left: 15.8vh;
      font-size: 12px;
    }
    .login{
      width: 7.5vh;
      height: 3vh;
      background-color: #21b97a;
      border: 0px solid #000;
      border-radius: 1vh;
      margin-left: 14vh;
      margin-top: 1.8vh;
      font-size: 11px;
      color: #fff;
    }
    .outlogin{
      width: 11.5vh;
      height: 3vh;
      background-color: #21b97a;
      border: 0px solid #000;
      border-radius: 1vh;
      margin-left: 18.3vh;
      margin-top: 1.8vh;
      font-size: 11px;
      color: #fff;
    }
    .usermsg{
      font-size: 10px;
      margin-top: 2vh;
      margin-left: 18.5vh;
          color: #999;
    }
    .yuan{
      width: 7vh;
      height: 7vh;
      background-color: #fff;
      border-radius: 50%;
      position: absolute;
      left: 50%;
      top: -3vh;
      transform: translateX(-3.5vh);
      box-shadow: 0 2px 2px #bdbdbd;
      .avatar {
        width: 6vh;
        height: 6vh;
        // background-color: red;
        background-image: url('@/assets/avatar.png');
        background-size: 100%;
        margin-left: 0.6vh;
        margin-top: 0.5vh;
      }
    }
  }
}
.up{
  width: 100%;
  height: 30vh;
  // background-color: red;
  position: relative;
  margin-bottom: 2vh;
  .uppic{
    width: 100%;
    height: 21.1vh;
    // background-color: saddlebrown;
    position: absolute;
    left: 0;
    top: 0;

      background-image: url('@/assets/bg.png');
      background: cover;

  }
  .updown{
    width: 35.2vh;
    height: 16.5vh;
    background-color: #fff;
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-17.5vh);
    // position: relative;
    box-shadow: 0 0 10px 3px #ddd;
    .you {
      margin-top: 6vh;
      margin-left: 12.2vh;
      font-size: 12px;
    }
    .youke{
      margin-top: 6vh;
      margin-left: 15.8vh;
      font-size: 12px;
    }
    .login{
      width: 9.5vh;
      height: 3vh;
      background-color: #21b97a;
      border: 0px solid #000;
      border-radius: 1vh;
      margin-left: 12.8vh;
      margin-top: 1.8vh;
      font-size: 11px;
      color: #fff;
    }
    .outlogin{
      width: 9.5vh;
      height: 3vh;
      background-color: #21b97a;
      border: 0px solid #000;
      border-radius: 1vh;
      margin-left: 12.8vh;
      margin-top: 1.8vh;
      font-size: 11px;
      color: #fff;
    }
    .usermsg{
      font-size: 10px;
      margin-top: 2vh;
      margin-left: 12vh;
          color: #999;
    }
    .yuan{
      width: 7vh;
      height: 7vh;
      background-color: #fff;
      border-radius: 50%;
      position: absolute;
      left: 50%;
      top: -3vh;
      transform: translateX(-3.5vh);
      box-shadow: 0 2px 2px #bdbdbd;
      .avatar {
        width: 6vh;
        height: 6vh;
        // background-color: red;
        background-image: url('@/assets/avatar.png');
        background-size: 100%;
        margin-left: 0.6vh;
        margin-top: 0.5vh;
      }
    }
  }
}
.downpic {
  width: 90%;
  height: 10vh;
  // background-color: sandybrown;
  background-image: url('@/assets/join.png');
  background-size: cover;
  margin-top: 2vh;
  margin-left: 3vh;
}
</style>
